home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 104_01.zip / STDLIB.ASM < prev    next >
Assembly Source File  |  1993-06-14  |  26KB  |  996 lines

  1.     title    small c i/o package
  2.     extrn    bios
  3. bdos    equ    5        ;address on entry address for bdos
  4. cpmcmd  equ    80h        ;address of cpm command line
  5. true    equ    1        ;value for true
  6. false    equ    0        ;value for false        
  7. ;
  8. ;    toupper
  9. ;
  10. ;    function: to shift lower case character to upper
  11. ;
  12. ;    calling format from "c"
  13. ;    toupper(char);
  14. ;
  15. toupper:csect
  16.     mov    a,l        ;get character to test
  17.     cpi    61h        ;check to see if less then 'a'
  18.     rc            ;yes return to caller
  19.     cpi    7bh        ;check to see if greater then 'z'
  20.     rnc            ;yes..return to caller
  21.     ani    5fh        ;mask off lowwer case bit
  22.     mov    l,a        ;put it in reg for return
  23.     ret            ;return to caller
  24. ;
  25. ;    tolowwer
  26. ;
  27. ;    function: to convert character to lowwer case
  28. ;
  29. ;    calling format from "c"
  30. ;    tolowwer(char)
  31. ;
  32. tolowwer:csect
  33.     mov    a,l        ;get character to shift to lowwer case
  34.     cpi    'A'        ;see if less then 'A'
  35.     rc            ;yes...return to caller
  36.     cpi    'Z'+1        ;see if greater then 'Z'
  37.     rnc            ;yes...return to caller
  38.     ani    0bfh        ;remove upper case bit
  39.     mov    l,a        ;put chracter back in place
  40.     ret
  41. ;
  42. ;    isalpha
  43. ;
  44. ;    function check to see if alpha character a-z or A-Z only
  45. ;
  46. ;    calling format from "c"
  47. ;    isalpha(char)
  48. ;
  49. isalpha:csect
  50.     push    h        ;save calling arg for later
  51.     call    isupper        ;check to see if upper case
  52.     xchg            ;put answer in de
  53.     pop    h        ;get character to test back
  54.     call    islowwer    ;check to see if lowwer case
  55.     dad    d        ;add isupper to is lowwer answer
  56.     ret
  57.  
  58. ;
  59. ;    isupper
  60. ;
  61. ;    function: to check to see if character is upper case
  62. ;
  63. ;    calling format in "c"
  64. ;    isupper(char) 
  65. ;
  66. isupper:csect
  67.     mov    a,l        ;get character to check
  68.     cpi    'A'        ;see if less then upper case a
  69.     jc    isupper1    ;not upper case
  70.     cpi    'Z'+1        ;check to see if less then 
  71.     jnc    isupper1    ;no upper case
  72.     lxi    h,true        ;yes it is upper case
  73.     ret
  74. isupper1:
  75.     lxi    h,false        ;not upper case
  76.     ret
  77. ;
  78. ;    islowwer
  79. ;
  80. ;    function: to check to see if character is lowwer case
  81. ;
  82. ;    calling format from "c"
  83. ;    islowwer(char)
  84. ;
  85. islowwer:csect
  86.     mov    a,l        ;get character to check
  87.     cpi    'a'        ;see if less then 'a'
  88.     jc    islowwer1    ;yes...not upper case
  89.     cpi    'z'+1        ;is it greater then 'z'
  90.     jnc    islowwer1    ;yes...not lower case
  91.     lxi    h,true        ;return true for lowwer case
  92.     ret
  93. islowwer1:
  94.     lxi    h,false        ;return false for anything but lowwer case
  95.     ret
  96. ;
  97. ;    isdigit
  98. ;
  99. ;    function: to check to see if character is digit 0-9 only
  100. ;
  101. ;    calling format from "c"
  102. ;    isdigit(char)
  103. ;
  104. isdigit:csect
  105.     mov    a,l        ;get character to test
  106.     cpi    '0'        ;see if less then a zero
  107.     jc    isdigit1    ;yes...not a vaild digit
  108.     cpi    '9'+1        ;is it greater than nine
  109.     jnc    isdigit1    ;yes...not a vaild digit
  110.     lxi    h,true        ;is a vaild digit
  111.     ret
  112. isdigit1:
  113.     lxi    h,false        ;not a vaild digit
  114.     ret
  115. ;
  116. ;    isspace
  117. ;
  118. ;    function: to check to see if white space tab or blank
  119. ;
  120. ;    calling format from "c"
  121. ;    isspace(char)
  122. ;
  123. isspace:csect
  124.     mov    a,l        ;get character to check
  125.     lxi    h,true        ;assume true
  126.     cpi    ' '        ;check for a space
  127.     rz
  128.     cpi    9        ;check for a tab
  129.     rz
  130.     lxi    h,false
  131.     ret
  132. ;
  133. ;    strlen
  134. ;
  135. ;    function: to get the lenght of a string
  136. ;
  137. ;    calling format in "c"
  138. ;    len=strlen(string);
  139. ;
  140. strlen:    csect
  141.     xchg            ;put address of string in de
  142.     lxi    h,0        ;make string of zero lenght
  143. strlen1:
  144.     ldax    d        ;get character from string
  145.     ora    a        ;check to see if end of string
  146.     rz            ;yes return to caller
  147.     inx    h        ;add 1 to string lenght
  148.     inx    d        ;move to next character
  149.     jmp    strlen1        ;loop till end of string found
  150. ;
  151. ;    strcpy
  152. ;
  153. ;    function: to copy first second string to first string
  154. ;
  155. ;    calling format from "c"
  156. ;    strcpy(object,source);
  157. ;
  158. strcpy:    csect
  159.     pop    b        ;get return address from stack
  160.     pop    d        ;get source address
  161.     pop    h        ;get object address
  162.     push    h        ;restore machine stack
  163.     push    d
  164.     push    b
  165.     push    h
  166. strcpy1:
  167.     ldax    d        ;get address of source  character
  168.     mov    m,a        ;store character in object string
  169.     ora    a        ;check to see if end of string
  170.     jz    strcpy2        ;end of string return to caller
  171.     inx    h
  172.     inx    d        ;move pointer to next byte
  173.     jmp    strcpy1        ;loop till done with copy
  174. strcpy2:
  175.     pop    h        ;return address of object string
  176.     ret
  177. ;
  178. ;    strcat
  179. ;
  180. ;    function: to put string2 at then end of string1 and return address of 
  181. ;                string 1
  182. ;
  183. ;    calling format in "c"
  184. ;    strcat(string1,string2);
  185. ;
  186. strcat:    csect
  187.     pop    b        ;get return address
  188.     pop    d        ;get address of string 2
  189.     pop    h        ;get address of string 1
  190.     push    h        ;retore machine stack
  191.     push    d
  192.     push    b
  193.     push    h        ;save address of source string
  194. strcat1:
  195.     mov    a,m        ;get character from source buffer
  196.     ora    a        ;check to see if zero
  197.     jz    strcat2        ;yes end of string found
  198.     inx    h        ;move pointer to next byte
  199.     jmp    strcat1        ;loop till end of string found
  200. strcat2:
  201.     ldax    d        ;get character from string 2
  202.     mov    m,a        ;save character in string1
  203.     ora    a        ;check to see if end of buffer
  204.     jz    strcat3        ;yes return to caller
  205.     inx    h        ;move object pointer up 1
  206.     inx    d        ;move source pointer up 1
  207.     jmp    strcat2
  208. strcat3:
  209.     pop    h        ;get address of string1
  210.     ret
  211. ;    strpos
  212. ;
  213. ;    function: to look for string 2 in string 1
  214. ;
  215. ;    calling format in "c"
  216. ;    strpos(string1,string2);
  217. ;
  218. strpos:    csect
  219.     call    argload        ;get args load into read be=1 de=2 hl=3
  220.     push    b
  221.     pop    h
  222.     lxi    b,1        ;de=string2, hl=string1 bc=0
  223.     xchg
  224. strpos1:
  225.     ldax    d        ;get character to check
  226.     ora    a        ;check to see if end of string
  227.     jz    strpos5        ;end of string1 string 2 not found in string1
  228.     cmp    m        ;is it equal to string2 character 1
  229.     jz    strpos2        ;yes...
  230.     inx    d        ;no add 1 to string 1 pointer
  231.     inx    b        ;add 1 to offset pointer
  232.     jmp    strpos1        ;loop till end of string1 or string2 found
  233. strpos2:
  234.     push    h        ;save strating address of string 21
  235.     push    d        ;save current address of string 1
  236. strpos3:
  237.     inx    d
  238.     inx    h
  239.     mov    a,m        ;get character from string 2
  240.     ora    a        ;set machine flags
  241.     jz    strpos4        ;end of string2 found must be a mathc
  242.     ldax    d        ;get arg1
  243.     cmp    m        ;is this character a match
  244.     jz    strpos3 
  245.     pop    d        ;restore pointer for string1 and string 2
  246.     pop    h
  247.     inx    d        ;add 1 to string pointer
  248.     inx    b        ;add 1 to offset in string1
  249.     jmp    strpos1        ;loop till end of string 1
  250. strpos4:
  251.     mov    l,c        ;string found return offset for caller
  252.     mov    h,b
  253.     pop    b
  254.     pop    b
  255.     ret
  256. strpos5:
  257.     lxi    h,0        ;string not found
  258.     ret
  259. ;
  260. ;    setmem
  261. ;
  262. ;    function: to fill a block of memory with a given constant
  263. ;
  264. ;    calling format in "c"
  265. ;    setmem(address,count,constant);
  266. ;
  267. setmem:    csect
  268.     pop    b        ;get return address
  269.     pop    h        ;get constant
  270.     mov    a,l        ;put constant in a
  271.     pop    b        ;get count
  272.     pop    d        ;get address
  273.     lxi    h,8        ;offset in to put stack back
  274.     dad    sp
  275.     sphl            ;restore stack pointer
  276.     mov    l,a        ;place to save constant
  277. setmem1:
  278.     mov    a,b        ;check to see if count is zero
  279.     ora    c
  280.     rz            ;all done with move
  281.     mov    a,l        ;get constant to store
  282.     stax    d        ;set memory loaction
  283.     inx    d        ;move pointer to next pointer
  284.     dcx    b        ;subtract 1 from count
  285.     jmp    setmem1        ;loop till all bytes set
  286. ;
  287. ;    movmem
  288. ;
  289. ;    function: to move source address to object address for count bytes
  290. ;
  291. ;    calling format from  "C"
  292. ;    movmem(source,object,count);
  293. ;
  294. movmem:    csect
  295.     call    argload        ;get args bc=1, de=2, hl=3
  296.     push    b        ;switch args so that 
  297.     push    d        ;bc=count
  298.     push    h        ;de=object
  299.     pop    b        ;hl=source
  300.     pop    h
  301.     pop    d
  302.     mov    a,b        ;check to see if count = 0
  303.     ora    c
  304.     rz            ;zero return to caller
  305.     call    movmemht    ;check to see if source<dest
  306.     jc    movmemt        ;move tial first
  307.     mvi    a,2        ;check to see if z80
  308.     inr    a
  309.     jpe    movmemf8    ;8080 do a byte by byte move
  310.     dw    0b0edh
  311.     ret
  312. movmemf8:
  313.     mov    a,m        ;get source byte
  314.     stax    d        ;save byte in object buffer
  315.     inx    h        ;move object pointer up 1
  316.     inx    d        ;move source pointer up 1 byte
  317.     dcx    b        ;subtract 1 from count
  318.     mov    a,b        ;see if done
  319.     ora    c
  320.     jnz    movmemf8    ;no keep on looping
  321.     ret
  322. movmemt:
  323.     dcx    b        ;tail first. compute new source
  324.     dad    b        ;and destination address
  325.     xchg
  326.     dad    b
  327.     xchg
  328.     mvi    a,2        ;check to see if z80
  329.     inr    a
  330.     jpe    movmemt8    ;8080 do a byte by byte move
  331.     dw    0b8edh
  332.     ret
  333. movmemt8:
  334.     mov    a,m        ;get source byte
  335.     stax    d        ;save object byte
  336.     dcx    h        ;move to next byte of source buffer
  337.     dcx    d        ;move to next byte of object buffer
  338.     dcx    b        ;subtract 1 from count
  339.     mov    a,b        ;cehck to see if all done
  340.     ora    c
  341.     jnz    movmemt8    ;no keep on looping
  342.     ret
  343. movmemht:
  344.     mov    a,h
  345.     cmp    d
  346.     rnz
  347.     mov    a,l
  348.     cmp    e
  349.     ret
  350. ;
  351. ;    outp
  352. ;
  353. ;    function: to output 1 byte to a data port
  354. ;
  355. ;    calling format from "C"
  356. ;    outp(port,data)
  357. ;
  358. outp:    csect
  359.     pop    b        ;get return address
  360.     pop    h        ;get data for port
  361.     pop    d        ;get port number
  362.     push    d        ;restore machine stack
  363.     push    h
  364.     push    b
  365.     mov    a,e        ;get port number
  366.     sta    outp1+1        ;save port number
  367.     mov    a,l        ;get data to send
  368. outp1:
  369.     out    0        ;send data to port
  370.     ret
  371. ;
  372. ;    inp
  373. ;
  374. ;    function: to input 1 byte from data port and return to caller
  375. ;
  376. ;    calling format in "c"
  377. ;    data=inp(port);
  378. ;
  379. inp:    csect
  380.     mov    a,l        ;get port number
  381.     sta    inp1+1        ;save port number for input
  382. inp1:
  383.     in    0        ;input data from port
  384.     mvi    h,0        ;zero high byte of number
  385.     mov    l,a        ;put data in reg for "c"
  386.     ret
  387. ;    
  388. ;    puts
  389. ;
  390. ;    function: to print a string to console ending with a null
  391. ;
  392. ;    call format from "C"
  393. ;
  394. ;    puts(string);
  395. ;
  396. puts:    csect
  397.     push    h        ;save calling address in stack
  398. puts1:  mov    a,m        ;get character to print
  399.     ora    a        ;check for zero
  400.     jz    puts2        ;if done return
  401.     push    h        ;save pointer for later user
  402.     mov    l,a        ;put character in reg for push
  403.     call    putch        ;print character on console
  404.     pop    h        ;get address of character back
  405.     inx    h        ;move to next character
  406.     jmp    puts1        ;loop till done with string
  407. puts2:
  408.     pop    h        ;get address of start of string
  409.     ret            ;return to caller
  410. ;
  411. ;    console i/o functions
  412. ;
  413. ;    putch
  414. ;
  415. ;    output 1 character to console and do not check 
  416. ;    to see if character is ready at console input
  417. ;
  418. ;    calling format from "C"
  419. ;    putch(c)
  420. ;
  421. putch:    csect
  422.     mov    a,l        ;get character to print
  423.     cpi    0ah        ;check for line feed
  424.     jnz    putch1        ;no.....
  425.     mvi    e,0dh        ;print return 
  426.     mvi    c,2        ;cpm print number function
  427.     call    bdos        ;print chararcer to console
  428.     mvi    l,0ah        ;print line feed
  429. putch1:
  430.     mov    e,l        ;put character in correct reg for call
  431.     mvi    c,2        ;cpm output function
  432.     call    bdos        ;print character to console
  433.     ret
  434. ;
  435. ;    function: to get 1 character from cpm console and return
  436. ;          character to caller
  437. ;
  438. ;    calling format in "C"
  439. ;    ch=getch();
  440. ;
  441. getch:  csect
  442.     mvi    c,1            ;cpm function number for getch
  443.     call    bdos            ;get character from console
  444.     cpi    0dh            ;check to see if a return
  445.     jnz    getch1          ;no check for a ^z end of file
  446.     mvi    d,0ah            ;send a lf to console
  447.     push    c            ;put it stack for putch
  448.     call    putch            ;print character on console
  449.     lxi    h,10            ;and return lf (new line)
  450.     ret
  451. getch1:
  452.     cpi    26            ;check to see if end of file
  453.     jnz    getch2          ;not a end of file return char.
  454.     lxi    h,-1            ;return end of file maker
  455.     ret                ;all done return to caller
  456. getch2:
  457.     mov    l,a            ;move character to return reg.
  458.     mvi    h,0            ;zero high byte of reutrn
  459.     ret
  460. ;
  461. ;    gets
  462. ;
  463. ;    function: to get a string from console and return address
  464. ;              of input string
  465. ;
  466. ;    calling format from "C"
  467. ;    gets(string);
  468. ;
  469. gets:    csect
  470.     push    h        ;save address of string
  471.     push    h
  472.     mvi    m,250        ;save for bdos call
  473.     mvi    c,10        ;cpm read string function
  474.     xchg            ;put address of string in de for cpm
  475.     call    bdos        ;call cpm to read string in
  476.     pop    d        ;get address of input string back
  477.     mov    h,d        ;put address in hl
  478.     mov    l,e
  479.     inx    d        ;move to lenght count
  480.     mov    b,m        ;get number of character in string
  481.     inx    d
  482. gets1:
  483.     ldax    d        ;get character from input buffer
  484.     mov    m,a        ;save character in buffer
  485.     inx    h        ;move pointer to next byte
  486.     inx    d    
  487.     dcr    b        ;see if all done with move
  488.     jnz    gets1         ;no keep on looping
  489. gets2:
  490.     mvi    m,0        ;put ending zero in stringo
  491.     mvi    c,2        ;cpm output character function
  492.     mvi    e,0ah        ;character to output
  493.     call    bdos        ;output a linefeed
  494.     pop    h        ;get address of iput string
  495.     ret            ;all done return to calleru
  496. ;
  497. ;    kbstat
  498. ;
  499. ;    funtion: to get status of cpm console returns
  500. ;    true or 1 if console character is ready or
  501. ;    0 if character is not ready
  502. ;
  503. ;    call format for c
  504. ;    kbstat()
  505. ;
  506. kbstat: csect
  507.     mvi    c,2        ;cpm function number for status check
  508.     push    b        ;send jump number out
  509.     push    b        ;arg
  510.     call    bios        ;call bios cons-stat
  511.     pop    b        ;remove args from stack
  512.     pop    b
  513.     mov    a,l        ;get return status from bios
  514.     ora    a        ;set machine status reg.
  515.     lxi    h,0        ;make it false (keyboard not ready)
  516.     rz            ;return to caller keyboard not ready
  517.     lxi    h,1        ;keyboard ready
  518.     ret            ;all done return to caller
  519. ;
  520. ;
  521. ;    open
  522. ;
  523. ;    function to build fcb and try to open file
  524. ;    address of fcb in de while name in hl. if file
  525. ;    is open ok then 0 is return else -1 is return
  526. ;
  527. ;    calling format from "C"
  528. ;    open(fcb,filename)
  529. ;
  530. open:    csect
  531.     pop    b        ;get return addess
  532.     pop    h        ;get address of file name
  533.     pop    d        ;address of fcb
  534.     push    d        ;put data back on stack
  535.     push    h
  536.     push    b
  537.     push    d        ;put address of fcb in stack
  538.     push    h        ;put address of file name in stack
  539.     call    setfcb        ;try to scan for a fcb
  540.     pop    d        ;remove address of file name from stack
  541.     pop    d        ;remove address of fcb from stack
  542.     inr    l        ;check to see if vaild return code
  543.     jz    open10        ;error invaild file name
  544.     mvi    c,15        ;cpm function to open a file
  545.     call    bdos        ;execute cpm open function
  546.     inr    a        ;see if error opening file
  547.     jz    open10        ;error file not found
  548.     lxi    h,0        ;set return code to zero
  549.     ret            ;return to caller
  550. open10:
  551.     lxi    h,-1        ;error return code
  552.     ret            ;return to caller
  553. ;
  554. ;    create
  555. ;
  556. ;    function to build fcb and delete file then
  557. ;    try to create file address of fcb in de 
  558. ;    while name in hl. if file is created ok
  559. ;    0 is return else -1 is return
  560. ;
  561. ;    calling format from "C"
  562. ;    create(fcb,filename)
  563. ;
  564. create:    csect
  565.     pop    b        ;get return address
  566.     pop    h        ;get address of file name
  567.     pop    d        ;get address of fcb
  568.      push    d        ;put data back on stack
  569.     push    h
  570.     push    b
  571.     push    d        ;set up arg list for setfcb
  572.     push    h
  573.     call    setfcb        ;try toscan and build fcb
  574.     pop    d        ;remove arg for setfcb from stack
  575.     pop    d
  576.     inr    l        ;see if error in file name
  577.     jz    create10    ;error in file name
  578.     push    d        ;save address of fcb
  579.     mvi    c,19        ;cpm function to delete a file
  580.     call    bdos        ;call bdos to do needed function
  581.     pop    d        ;restore address of fcb to create
  582.     mvi    c,22        ;cpm function to make file
  583.     call    bdos        ;call bods to do needed function
  584.     inr    a        ;check to see if error
  585.     jz    create10    ;error unable to creat file
  586.     lxi    h,0        ;every thing ok set return code to zero
  587.     ret            ;return to caller
  588. create10:
  589.     lxi    h,-1        ;error set return code to -1
  590.     ret
  591. ;
  592. ;    close
  593. ;
  594. ;    function to close a file that is current open.
  595. ;    address of fcb in de. if able to close file o is
  596. ;    is return or -1 if unable to close
  597. ;
  598. ;    calling format from "C"
  599. ;    close(fcb)
  600. ;
  601. close:    csect
  602.     pop    b        ;return address
  603.     pop    d        ;address of fcb
  604.     push    d        ;put data back in stack
  605.     push    b
  606.     mvi    c,16        ;cpm function to close a file
  607.     call    bdos        ;call cpm to do needed function
  608.     inr    a        ;check for errors
  609.     jz    close10        ;error unable to close file
  610.     lxi    h,0        ;every thing is ok set return code to zero
  611.     ret            ;return to caller
  612. close10:
  613.     lxi    h,-1        ;error set return code to error
  614.     ret
  615. ;
  616. ;    unlink
  617. ;
  618. ;    function to build fcb and try to delete
  619. ;    delete file. if ok return 0 else -1
  620. ;
  621. ;    calling format from "C"
  622. ;    unlink(filename)
  623. ;
  624. unlink:    csect
  625.     pop    b        ;get return address
  626.     pop    d        ;get address of file name
  627.     push    d        ;put data back in stack
  628.     push    b
  629.     lxi    h,-36        ;put stack pointer in hl
  630.     dad    sp        ;address of stack in hl
  631.     sphl            ;set new address of stack pointer
  632.     lxi    b,36        ;get address of fcb for delete
  633.     dad    b        ;add to get base for fcb
  634.     push    h        ;set up arg for setfcb
  635.     push    d
  636.     call    setfcb        ;try to build fcb
  637.     pop    d        ;remove arg for setfcb
  638.     pop    d
  639.     inr    l        ;see if error
  640.     jz    unlink10    ;error not a vaild file name
  641.     mvi    c,19        ;function number to delete a file
  642.     call    bdos        ;call cpm to delete file from system
  643.     inr    a        ;check to see if in error
  644.     jz    unlink10    ;error unable to delete file
  645.     lxi    d,0        ;return code
  646.     jmp    unlink11    ;reset stack pointer
  647. unlink10:
  648.     lxi    d,-1        ;set error code 
  649. unlink11:
  650.     lxi    h,36        ;number of byte to move back
  651.     dad    sp        ;add to current stack pointer
  652.     sphl            ;put new value in stack pointer
  653.     xchg            ;put return code in hl
  654.     ret            ;all done return to caller
  655. ;
  656. ;    read
  657. ;
  658. ;    function to read x record from disk and return
  659. ;    number of record read or -1
  660. ;
  661. ;    calling format from "C"
  662. ;    read(fcb,buffer,count);
  663. ;
  664. read:    csect
  665.     lxi    h,2        ;offset in stack till count
  666.     dad    sp        ;get address of number of record to read
  667.     mov    a,m        ;get low byte of count
  668.     mov    e,m        ;save for later use
  669.     inx    h        ;move to high byte of count
  670.     ora    m        ;see if 16 bit count is zero
  671.     mov    d,m        ;get high byte of count 
  672.     jz    read1        ;yes do not read any more records
  673.     dcx    d        ;subtract 1 from count
  674.     mov    m,d        ;put high byte back
  675.     dcx    h        ;point to high byte
  676.     mov    m,e        ;save low byte
  677.     inx    h        ;move to buffer address
  678.     inx    h
  679.     mov    e,m        ;get address of buffer
  680.     inx    h        ;move to high byte of address
  681.     push    h        ;save current pointer on stack
  682.     mov    d,m        ;get high byte of address
  683.     mvi    c,26        ;set dma address
  684.     call    bdos        ;call cpm to set buffer address
  685.     pop    h        ;remove current pointer from stack
  686.     inx    h        ;move to address of fcb
  687.     push    h        ;put current pointer back on stack
  688.     mov    e,m        ;get low byte of fcb address
  689.     inx    h        ;move to high byte of address
  690.     mov    d,m        ;get high address of fcb
  691.     mvi    c,20        ;read record from dsik
  692.     call    bdos        ;call cpm to do it
  693.     pop    h        ;get current pointer back
  694.     ora    a        ;check for errors
  695.     jnz    read2        ;error reading file from disk
  696.     dcx    h        ;move to address of buffer
  697.     mov    d,m        ;get high byte of address
  698.     dcx    h        ;move to low  byte of address
  699.     mov    e,m        ;get low byte of address
  700.     xchg            ;put address in hl and varble address in hl
  701.     lxi    b,80h        ;lenght of 1 record on disk
  702.     dad    b        ;add sector lenght to buffer address
  703.     xchg            ;put buffer address back in de
  704.     mov    m,e        ;save new low byte of address
  705.     inx    h        ;move to high byte of address
  706.     mov    m,d        ;save high byte of address
  707.     jmp    read        ;see it time to read next record
  708. read1:
  709.     lxi    h,0        ;every thing is ok return to caller
  710.     jmp    read3        ;set dma address to tbuf and return
  711. read2:
  712.     lxi    h,-1        ;error reading file
  713. read3:
  714.     push    h        ;save return code
  715.     lxi    d,cpmcmd    ;address of temp buff
  716.     mvi    c,26        ;set dma address function
  717.     call    bdos        ;call cpm to do needed funtion
  718.     pop    h        ;get return code from stack
  719.     ret            ;all done return to caller
  720. ;
  721. ;    function to write x record from    disk and return
  722. ;    false if no errors or true if error
  723. ;
  724. ;    calling format from "C"
  725. ;    write(fcb,buffer,count);
  726. ;
  727. write:    csect
  728.     lxi    h,2        ;offset in stack till count
  729.     dad    sp        ;get address of number of record to read
  730.     mov    a,m        ;get low byte of count
  731.     mov    e,m        ;save for later use
  732.     inx    h        ;move to high byte of count
  733.     ora    m        ;see if 16 bit count is zero
  734.     mov    d,m        ;get high byte of count 
  735.     jz    write1        ;yes do    not write any more records
  736.     dcx    d        ;subtract 1 from count
  737.     mov    m,d        ;put high byte back
  738.     dcx    h        ;point to high byte
  739.     mov    m,e        ;save low byte
  740.     inx    h        ;move to buffer address
  741.     inx    h
  742.     mov    e,m        ;get address of buffer
  743.     inx    h        ;move to high byte of address
  744.     push    h        ;save current pointer on stack
  745.     mov    d,m        ;get high byte of address
  746.     mvi    c,26        ;set dma address
  747.     call    bdos        ;call cpm to set buffer address
  748.     pop    h        ;remove current pointer from stack
  749.     inx    h        ;move to address of fcb
  750.     push    h        ;put current pointer back on stack
  751.     mov    e,m        ;get low byte of fcb address
  752.     inx    h        ;move to high byte of address
  753.     mov    d,m        ;get high address of fcb
  754.     mvi    c,21        ;write record to disk
  755.     call    bdos        ;call cpm to do it
  756.     pop    h        ;get current pointer back
  757.     ora    a        ;check for errors
  758.     jnz    write2        ;error writing file from disk
  759.     dcx    h        ;move to address of buffer
  760.     mov    d,m        ;get high byte of address
  761.     dcx    h        ;move to low  byte of address
  762.     mov    e,m        ;get low byte of address
  763.     xchg            ;put address in hl and varble address in hl
  764.     lxi    b,80h        ;lenght of 1 record on disk
  765.     dad    b        ;add sector lenght to buffer address
  766.     xchg            ;put buffer address back in de
  767.     mov    m,e        ;save new low byte of address
  768.     inx    h        ;move to high byte of address
  769.     mov    m,d        ;save high byte of address
  770.     jmp    write        ;see it    time to    write next record
  771. write1:
  772.     lxi    h,0        ;every thing is ok return to caller
  773.     jmp    write3        ;set dma address to tbuf and return
  774. write2:
  775.     lxi    h,-1        ;error writing file
  776. write3:
  777.     push    h        ;save return code
  778.     lxi    d,cpmcmd    ;address of temp buff
  779.     mvi    c,26        ;set dma address function
  780.     call    bdos        ;call cpm to do needed funtion
  781.     pop    h        ;get return code from stack
  782.     ret            ;all done return to caller
  783. ;
  784. ;    setfcb
  785. ;
  786. ;    function to build fcb for file name pointed to in hl and
  787. ;    address of fcb in de 
  788. ;
  789. ;    calling format from "C"
  790. ;    setfcb(fcb,filename);
  791. ;
  792. setfcb:    csect
  793.     pop    b        ;get return address
  794.     pop    h        ;address of file name
  795.     pop    d        ;address of fcb
  796.     push    d        ;put data back on stack
  797.     push    h
  798.     push    b
  799.     dcx    h        ;set pointer back 1 before file name
  800. setfcb1:
  801.     inx    h        ;move pointer to next chracter
  802.     mov    a,m        ;get character from buffer
  803.     ora    a        ;check for end of buffer
  804.     jz    setfcb6        ;error null file name
  805.     cpi    ' '        ;see if leading space 
  806.     jz    setfcb1        ;yes move to next character
  807.     push    h        ;save starting address of file name
  808. setfcb1a:
  809.     mov    a,m        ;get character from file name
  810.     ora    a        ;see if end of string
  811.     jz    setfcb1b    ;yes... loop back till not space
  812.     inx    h        ;move to next byte
  813.     jmp    setfcb1a
  814. setfcb1b:
  815.     dcx    h        ;move back 1 character
  816.     mov    a,m        ;get this chracter from buffer
  817.     cpi    ' '        ;is this character a space
  818.     jz    setfcb1b    ;loop till none space character is found
  819.     inx    h        ;move to end of string
  820.     mvi    m,0        ;move end of string marker
  821.     pop    h        ;get starting address back
  822.     inx    h        ;move to ":" if disk spec
  823.     mov    a,m        ;get this character form file name
  824.     dcx    h        ;put pointer back
  825.     cpi    ':'        ;see if disk spec in file name 
  826.     jnz    setfcb2        ;no gt ready for file name
  827.     mov    a,m        ;get disk name
  828.     call    setfcb10        ;make if upper case
  829.     sui    '@'        ;make it 01-16 for disk a-p
  830.     inx    h        ;move to start of file name
  831.     inx    h
  832.     jmp    setfcb3        ;move disk value into fcb
  833. setfcb2:
  834.     xra    a        ;make defualt disk
  835. setfcb3:
  836.     stax    d        ;save value for disk drive    
  837.     inx    d        ;move fcb to file name
  838.     mvi    b,8        ;number of byte in file name
  839.     call    setfcb11    ;move file name into place
  840.     jnz    setfcb6        ;see if bad character in file name
  841.     cpi    '.'        ;chek to see if file type
  842.     jnz    setfcb4        ;no do not move pointer past '.'
  843.     inx    h        ;move to file type byte
  844. setfcb4:
  845.     mvi    b,3        ;number of bytes in file type
  846.     call    setfcb11    ;move file type into fcb
  847.     jnz    setfcb6        ;see if bad character in file type
  848.     mvi    b,24        ;number of bytes left in fcb
  849.     mvi    a,0        ;value to file fcb with
  850. setfcb5:
  851.     stax    d        ;put 0 in fcb ex-r2
  852.     inx    d        ;move to next byte
  853.     dcr    b        ;see if done with move
  854.     jnz    setfcb5        ;no keep on moveing
  855.     lxi    h,0        ;return false if no errors
  856.     ret
  857. setfcb6:
  858.     lxi    h,-1        ;return -1 if bad character in file name
  859.     ret
  860. ;
  861. ;    shift character to upper case
  862. ;
  863. setfcb10:
  864.     cpi    061h        ;is it less then lowwer case a
  865.     rc            ;yes...
  866.     cpi    07ah        ;is it greater then lowwer case z
  867.     rnc            ;yes
  868.     ani    05fh        ;make it loower case
  869.     ret
  870. ;
  871. ;    scan b characters and move into fcb checking for "?" and
  872. ;    bad character in file name
  873. ;
  874. setfcb11:
  875.     mov    a,m        ;get character form file name
  876.     cpi    '*'        ;is it a wild card
  877.     mvi    a,'?'        ;yes make it all ???
  878.     jz    setfcb114    ;make all ???
  879. setfcb112:
  880.     mov    a,m        ;get character to check
  881.     call    setfcb12    ;get and check to see if vaild        
  882.     jc    setfcb113    ;no....
  883.     stax    d        ;save character in fcb
  884.     inx    h        ;move both pointers up by 1 bye
  885.     inx    d
  886.     dcr    b        ;see if  done with file name
  887.     jnz    setfcb11    ;no keep on moveing
  888.     jmp    setfcb115    ;done with file look for ending char
  889. setfcb113:
  890.     ora    a        ;check to see if end of file name
  891.     jz    setfcb113a    ;yes...
  892.     cpi    '.'        ;check for delimter
  893.     rnz            ;no return and show error
  894. setfcb113a:
  895.     mvi    a,' '        ;done with field  pad with blanks
  896. setfcb114:
  897.     stax    d        ;fill fcb with value
  898.     inx    d        ;move to next byte of fcb
  899.     dcr    b        ;see if done with move
  900.     jnz    setfcb114    ;no keep on filling
  901. setfcb115:
  902.     mov    a,m        ;get character from file name
  903.     ora    a
  904.     rz
  905.     cpi    '.'        ;check for '.'
  906.     rz
  907.     inx    h
  908.     jmp    setfcb115    ;not ending character keep on looking
  909. ;
  910. ;    check to see if vaild character for fcb a-z and 0-9 only
  911. ;    set carry if not a vaild character otherwise reset carry
  912. ;
  913. setfcb12:
  914.     call    setfcb10    ;upper case character
  915.     cpi    '?'        ;wild card character
  916.     jz    setfcb121    ;yes vaild character
  917.     cpi    '$'        ;needed for submit files
  918.     jz    setfcb121    ;yes valid character
  919.     cpi    '0'        ;is it less then '0'
  920.     rc            ;yes error invaild character
  921.     cpi    '9'+1        ;is it greater then 0 and less then eq 9
  922.     jc    setfcb121    ;yes vaild character
  923.     cpi    'A'        ;is it less then 'A'
  924.     rc            ;yes error between '9' and 'A'
  925.     cpi    'Z'+1        ;is it between 'A' and 'Z' 
  926.     cmc            ;flop carry bit
  927.     ret
  928. setfcb121:
  929.     stc            ;set carry flag
  930.     cmc            ;set carry off
  931.     ret
  932. ;
  933. ;    rsvstk
  934. ;
  935. ;    function: to set how close to go to machine stack pointer
  936. ;
  937. ;    calling format in "C"
  938. ;    rsvstk(amount);
  939. ;
  940. rsvstk:    csect
  941.     shld    @alocmx        ;save number of bytes not to used
  942.     ret
  943. ;
  944. ;    storinit
  945. ;
  946. ;    function: to init stroage allocation system
  947. ;
  948. ;    calling format from "c"
  949. ;    storinit();
  950. ;
  951. storinit:csect
  952.     lxi    h,@base_free    ;get address of start of free list
  953.     shld    @base_free    ;save as first element
  954.     shld    @allocp        ;save as pointer to last block
  955.     lxi    h,0        ;get size of free list area
  956.     sta    @base_free+2    ;save as current size of free area
  957.     lxi    h,3000        ;size of memory not to use
  958.     shld    @alocmx        ;save it for later use
  959.     ret
  960. ;
  961. ;    data area used for free storage mangment
  962. ;
  963. @free_list:dsect
  964. @Base_free:    ds    4
  965. @allocp:    ds    2
  966. @alocmx        ds    2
  967. ;
  968. ;    argload
  969. ;
  970. ;    function to load bc with arg back 3 de with arg back 2 hl with
  971. ;         1 back
  972. argload:csect
  973.     lxi    h,8        ;offset in stack for arg for bc
  974.     dad    sp        ;add to stack pointer
  975.     mov    c,m
  976.     inx    h
  977.     mov    b,m
  978.     inx    h
  979.     mov    e,m
  980.     inx    h
  981.     mov    d,m
  982.     inx    h
  983.     mov    a,m
  984.     inx    h
  985.     mov    h,m
  986.     mov    l,a
  987.     ret
  988.  
  989.  
  990. inx    h
  991.     mov    h,m
  992.     mov    l,a
  993.     ret
  994.  
  995.  
  996.     st